#include "mylist.hpp"
#include <string>
#include <cstdlib>

void TestList1()
{
    cout << "==========" << endl;

    // 测试构造函数
    bite::list<int> l1;                  // 测试默认构造
    bite::list<int> l2(4, 100);         // 测试带参构造
    
    cout << "l2的内容: ";
    for(auto e : l2)
        cout << e << " ";
    cout << endl;

    // 测试迭代器构造
    int arr[] = {1,2,3,4,5};
    bite::list<int> l3(arr, arr + sizeof(arr)/sizeof(int));
    cout << "l3的内容: ";
    for(auto e : l3)
        cout << e << " ";
    cout << endl;


    // 测试拷贝构造
    bite::list<int> l4(l3);
    cout << "l4的内容: ";
    for(auto e : l4)
        cout << e << " ";
    cout << endl;
}

void TestList2()
{
    cout << "\n=====测试修改操作=====" << endl;
    bite::list<string> l;
    
    // 测试push_back/front
    l.push_back("world");
    l.push_front("hello");
    
    cout << "l的内容: ";
    for(auto& e : l)
        cout << e << " ";
    cout << endl;

    // 测试insert
    auto it = l.begin();
    ++it;
    l.insert(it, "beautiful");
    
    cout << "插入后l的内容: ";
    for(auto& e : l)
        cout << e << " ";
    cout << endl;

    // 测试erase
    it = l.begin();
    l.erase(++it);
    
    cout << "删除后l的内容: ";
    for(auto& e : l)
        cout << e << " ";
    cout << endl;
}

void TestList3()
{
    cout << "\n=====测试容量相关操作=====" << endl;
    bite::list<int> l;
    cout << "空链表判断：" << l.empty() << endl;
    
    l.push_back(1);
    l.push_back(2);
    l.push_back(3);
    
    cout << "size: " << l.size() << endl;
    cout << "front: " << l.front() << endl;
    cout << "back: " << l.back() << endl;
    
    // 测试clear
    l.clear();
    cout << "clear后，empty: " << l.empty() << endl;
}

int main()
{


    system("chcp 65001");


    TestList1();
    TestList2();
    TestList3();
    
    return 0;
}







